/*   1:    */ package com.rinsi.util;
/*   2:    */ 
/*   3:    */ import com.sun.crypto.provider.SunJCE;
/*   4:    */ import java.security.Key;
/*   5:    */ import java.security.Security;
/*   6:    */ import javax.crypto.Cipher;
/*   7:    */ import javax.crypto.spec.SecretKeySpec;
/*   8:    */ 
/*   9:    */ public class CodeUtil
/*  10:    */ {
/*  11: 13 */   private static String strDefaultKey = "zhaobinhu";
/*  12: 15 */   private static CodeUtil ccu = new CodeUtil();
/*  13: 17 */   private Cipher encryptCipher = null;
/*  14: 19 */   private Cipher decryptCipher = null;
/*  15:    */   
/*  16:    */   public static String byteArr2HexStr(byte[] arrB)
/*  17:    */   {
/*  18: 26 */     int iLen = arrB.length;
/*  19:    */     
/*  20: 28 */     StringBuffer sb = new StringBuffer(iLen * 2);
/*  21: 30 */     for (int i = 0; i < iLen; i++)
/*  22:    */     {
/*  23: 32 */       int intTmp = arrB[i];
/*  24: 34 */       while (intTmp < 0) {
/*  25: 36 */         intTmp += 256;
/*  26:    */       }
/*  27: 38 */       if (intTmp < 16) {
/*  28: 40 */         sb.append("0");
/*  29:    */       }
/*  30: 42 */       sb.append(Integer.toString(intTmp, 16));
/*  31:    */     }
/*  32: 45 */     return sb.toString();
/*  33:    */   }
/*  34:    */   
/*  35:    */   public static byte[] hexStr2ByteArr(String strIn)
/*  36:    */   {
/*  37: 54 */     byte[] arrB = strIn.getBytes();
/*  38:    */     
/*  39: 56 */     int iLen = arrB.length;
/*  40:    */     
/*  41: 58 */     byte[] arrOut = new byte[iLen / 2];
/*  42: 60 */     for (int i = 0; i < iLen; i += 2)
/*  43:    */     {
/*  44: 62 */       String strTmp = new String(arrB, i, 2);
/*  45:    */       
/*  46: 64 */       arrOut[(i / 2)] = ((byte)Integer.parseInt(strTmp, 16));
/*  47:    */     }
/*  48: 67 */     return arrOut;
/*  49:    */   }
/*  50:    */   
/*  51:    */   private CodeUtil()
/*  52:    */   {
/*  53: 73 */     this(strDefaultKey);
/*  54:    */   }
/*  55:    */   
/*  56:    */   private CodeUtil(String strKey)
/*  57:    */   {
/*  58: 78 */     Security.addProvider(new SunJCE());
/*  59:    */     try
/*  60:    */     {
/*  61: 81 */       Key key = getKey(strKey.getBytes());
/*  62:    */       
/*  63: 83 */       this.encryptCipher = Cipher.getInstance("DES");
/*  64:    */       
/*  65: 85 */       this.encryptCipher.init(1, key);
/*  66:    */       
/*  67: 87 */       this.decryptCipher = Cipher.getInstance("DES");
/*  68:    */       
/*  69: 89 */       this.decryptCipher.init(2, key);
/*  70:    */     }
/*  71:    */     catch (Exception e)
/*  72:    */     {
/*  73: 93 */       e.printStackTrace();
/*  74:    */     }
/*  75:    */   }
/*  76:    */   
/*  77:    */   public byte[] encrypt(byte[] arrB)
/*  78:    */   {
/*  79: 99 */     byte[] encrypt = null;
/*  80:    */     try
/*  81:    */     {
/*  82:103 */       encrypt = this.encryptCipher.doFinal(arrB);
/*  83:    */     }
/*  84:    */     catch (Exception e)
/*  85:    */     {
/*  86:107 */       e.printStackTrace();
/*  87:    */     }
/*  88:110 */     return encrypt;
/*  89:    */   }
/*  90:    */   
/*  91:    */   public static String code(String strIn)
/*  92:    */   {
/*  93:119 */     return byteArr2HexStr(ccu.encrypt(strIn.getBytes()));
/*  94:    */   }
/*  95:    */   
/*  96:    */   public byte[] decrypt(byte[] arrB)
/*  97:    */   {
/*  98:124 */     byte[] decrypt = null;
/*  99:    */     try
/* 100:    */     {
/* 101:128 */       decrypt = this.decryptCipher.doFinal(arrB);
/* 102:    */     }
/* 103:    */     catch (Exception e)
/* 104:    */     {
/* 105:132 */       return arrB;
/* 106:    */     }
/* 107:134 */     return decrypt;
/* 108:    */   }
/* 109:    */   
/* 110:    */   public static String decode(String strIn)
/* 111:    */   {
/* 112:142 */     return new String(ccu.decrypt(hexStr2ByteArr(strIn)));
/* 113:    */   }
/* 114:    */   
/* 115:    */   private Key getKey(byte[] arrBTmp)
/* 116:    */     throws Exception
/* 117:    */   {
/* 118:147 */     byte[] arrB = new byte[8];
/* 119:149 */     for (int i = 0; (i < arrBTmp.length) && (i < arrB.length); i++) {
/* 120:150 */       arrB[i] = arrBTmp[i];
/* 121:    */     }
/* 122:153 */     Key key = new SecretKeySpec(arrB, "DES");
/* 123:    */     
/* 124:155 */     return key;
/* 125:    */   }
/* 126:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.util.CodeUtil
 * JD-Core Version:    0.7.0.1
 */